18. Solution: Integration Testing
Solution: Integration Testing
ND079 JPND C3 L5 A12 Solution Integration Testing
TimeZoneServiceTest.java
@ExtendWith(MockitoExtension.class)
class TimeZoneServiceTest {
static WireMockServer wireMock = new WireMockServer(wireMockConfig().port(8089));
private TimeZoneService timeZoneService;
@BeforeAll
static void setup() {
wireMock.start();
}
@AfterAll
static void cleanup() {
wireMock.stop();
}
@BeforeEach
void init() {
wireMock.resetAll();
timeZoneService = new TimeZoneService("http://localhost:8089");
}
@Test
void getAvailableTimezoneText_timeApiReturnsStringList_returnsCountriesAsString() {
wireMock.stubFor(
get(urlEqualTo("/api/timezone/Europe"))
.willReturn(
aResponse()
.withStatus(200)
.withBody("[\"Amsterdam\", \"Andorra\", \"Astrakhan\", \"Athens\"]")
)
);
String availableTimezoneText = timeZoneService.getAvailableTimezoneText("Europe");
assertTrue(availableTimezoneText.contains("Available timezones in Europe are Amsterdam, Andorra"));
}
}